package designs.models.memento;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Caretaker {
	File file;
	private Memento memento = null;
	Caretaker(){
		file = new File("src/designs/models/memento/saveObject.txt");
	}
	
	public Memento getMemento() {
		if (file.exists()) {
			try {
				//FileInputStream in = new FileInputStream(new File("src/designs/models/memento/saveObject.txt"));
				FileInputStream in = new FileInputStream(file);
				ObjectInputStream inObject = new ObjectInputStream(in);
				memento = (Memento) inObject.readObject();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return memento;
	}
	
	public void saveMemento(Memento memento) {
		try {
			//FileOutputStream out = new FileOutputStream("src/designs/models/memento/saveObject.txt");
			FileOutputStream out = new FileOutputStream(file);
			ObjectOutputStream outObject = new ObjectOutputStream(out);
			outObject.writeObject(memento);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
